﻿using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
namespace Common
{
    public class Log
    {
        public static LogLevel Level = LogLevel.Debug;
        public static bool OutputLog = true;
        public static void Debug(string msg)
        {
            if (Level <= LogLevel.Debug) output(msg);
        }
        public static void Info(string msg)
        {
            if (Level <= LogLevel.Info) output(msg);
        }
        public static void Warning(string msg)
        {
            if (Level <= LogLevel.Warning) output(msg);
        }
        public static void Error(string msg)
        {
            if (Level <= LogLevel.Error) output(msg);
        }
        private static void output(string msg)
        {
            UnityEngine.Debug.Log(msg);
            if (OutputLog) LogString += msg + "\r\n";
        }
        public static void OnGUI()
        {
            if (OutputLog)
            {
                GUILayout.BeginArea(new Rect(300, 10, 400, 200));
                scrollPosition = GUILayout.BeginScrollView(scrollPosition);
                LogString = GUILayout.TextArea(LogString);
                GUILayout.EndScrollView();
                GUILayout.EndArea();
            }
        }
        private static string LogString = string.Empty;
        private static Vector2 scrollPosition = Vector2.zero;
    }
    [Flags]
    public enum LogLevel
    {
        Debug = 0,
        Info,
        Warning,
        Error
    }
}

